package org.byqh.dqeai.dto.common;

import com.easy.query.core.api.pagination.EasyPageResult;
import lombok.Getter;

import java.util.List;

public class IPage<T> {
    @Getter
    private final long current;
    @Getter
    private final long size;

    private final EasyPageResult<T> easyPageResult;

    public IPage(long current, long size, EasyPageResult<T> easyPageResult) {
        this.current = current;
        this.size = size;
        this.easyPageResult = easyPageResult;
    }

    public List<T> getRecords() {
        return easyPageResult.getData();
    }

    public long getTotal() {
        return easyPageResult.getTotal();
    }

    public long getPages() {
        if (this.getSize() == 0L) {
            return 0L;
        } else {
            long pages = this.getTotal() / this.getSize();
            if (this.getTotal() % this.getSize() != 0L) {
                ++pages;
            }

            return pages;
        }
    }
}
